package com.ruoyi.passenger.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.passenger.domain.UserQueryHistory;
import com.ruoyi.passenger.service.IUserQueryHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/history")
public class UserQueryHistoryController extends BaseController
{
    @Autowired
    private IUserQueryHistoryService userQueryHistoryService;

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("driver:history:list")
    @GetMapping("/list")
    public TableDataInfo list(UserQueryHistory userQueryHistory)
    {
        startPage();
        List<UserQueryHistory> list = userQueryHistoryService.selectUserQueryHistoryList(userQueryHistory);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("driver:history:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserQueryHistory userQueryHistory)
    {
        List<UserQueryHistory> list = userQueryHistoryService.selectUserQueryHistoryList(userQueryHistory);
        ExcelUtil<UserQueryHistory> util = new ExcelUtil<UserQueryHistory>(UserQueryHistory.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @RequiresPermissions("driver:history:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userQueryHistoryService.selectUserQueryHistoryById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @RequiresPermissions("driver:history:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserQueryHistory userQueryHistory)
    {
        return toAjax(userQueryHistoryService.insertUserQueryHistory(userQueryHistory));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("driver:history:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserQueryHistory userQueryHistory)
    {
        return toAjax(userQueryHistoryService.updateUserQueryHistory(userQueryHistory));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("driver:history:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userQueryHistoryService.deleteUserQueryHistoryByIds(ids));
    }

    @GetMapping("seluserqueryhistory")
    public AjaxResult selUserQueryHistory(){
        Long userId = SecurityUtils.getUserId();
        List<UserQueryHistory> list = userQueryHistoryService.selUserQueryHistory(userId);
        return AjaxResult.success(list);
    }


    @PostMapping("saveuserqueryhistory")
    public AjaxResult saveUserQueryHistory(@RequestBody UserQueryHistory userQueryHistory){
        userQueryHistory.setQueryTime(new Date());
        userQueryHistory.setUserId(SecurityUtils.getUserId());
        userQueryHistoryService.insertUserQueryHistory(userQueryHistory);
        return AjaxResult.success();
    }
}
